home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
network
/
ka9q
/
ka9q_src.arc
/
ST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-12-02
|
18KB
|
855 lines
/* OS- and machine-dependent stuff for Atari-ST
* Adapted from the PC version to compile under Lattice C
* by Walter Doerr, DG2KK (dg2kk@cup.portal.com)
*
* 20-2-88: added code from the Atari MWC version by Rob Janssen PE1CHL
* 13-1-88: added code needed for the 871225.1 version
* 24-12-87: first version, adapted from PC.C from the 870412 release
*/
#include "stdio.h"
#include "global.h"
#include "config.h"
#include "mbuf.h"
#include "internet.h"
#include "iface.h"
#include "st.h"
#include "cmdparse.h"
/* #include "stdlib.h" chkml() , malloc , free */
#ifdef LATTICE
#include "dos.h" /* dfind */
#endif
#include "osbind.h"
#ifdef MWC
#include <stat.h>
FILE *stdprt;
extern char **environ;
#endif
#define TRUE -1
#define FALSE 0
struct asy asy[ASY_MAX];
/* Interface list header */
struct interface *ifaces;
unsigned nasy; /* needed in v871225.1 */
char *ttbuf;
char *rsbuf; /* location of memory alloc'd for rs232 buf */
#ifdef SCREEN
char *newscreen, *newscradr; /* 32k memory allocated to 2nd video screen */
long logscreen, physcreen;
int toggle = 0; /* toggle between normal and trace screen */
int printtrace = 0; /* send trace to printer (controlled by F2) */
#endif
char *shell,*getenv(); /* Name of command shell for exec */
int rows=25; /* Number of text rows on screen (may be 50) */
/* called during init b4 anything is printed on the screen.
* PC.C does a lot of memory allocation stuff here.
* We just set the cursor to "blink" and allocate memory for a second video
* screen.
*/
ioinit()
{
char *lmalloc(); /* Takes a long arg */
unsigned long ptr;
#ifdef SCREEN
newscradr = lmalloc(32*1024L); /* allocate 32k for 2nd video screen */
ptr = (unsigned long)newscradr;
newscreen = (char *)((ptr+255) & 0xffffff00L); /* 256 byte boundary */
physcreen = (long)Physbase(); /* remember displayed screen address */
logscreen = (long)Logbase(); /* remember output screen address */
Cconws("\033j"); /* Save cursor position */
(void) Setscreen(newscreen,-1L,-1); /* switch to 2nd screen */
(void) Vsync(); /* wait for vsync */
Cconws("\033H\033J"); /* cursor home, clear screen */
Cconws("\033k"); /* restore cursor position */
(void) Setscreen(logscreen,-1L,-1); /* restore old screen */
(void) Vsync(); /* wait for vsync */
#endif
printf("\033v\033e\n"); /* Autowrap on, Cursor on */
(void) Cursconf(2,0); /* make the cursor blink (3=steady) */
#ifdef MWC
stdprt = fopen("prn:","w");
#endif
shell = getenv("NROWS");
if (shell != NULL)
rows=atoi(shell);
shell = getenv("SHELL");
if (shell == NULL)
shell="\\bin\\gulam.prg";
}
/* Called just before exiting.
* delete temp files.
* free memory allocated to the rs-232 and midi buffers.
*/
iostop()
{
/* free memory allocated to 2nd video screen */
#ifdef SCREEN
dispscreen(0); /* switch back to original screen */
free(newscradr);
#endif
/* delete all temp files that have accumulated */
(void) tmpdel();
/* free memory allocated to RS-232/MIDI I/O buffers */
while (ifaces != NULLIF) {
if (ifaces->stop != NULLFP)
(*ifaces->stop)(ifaces);
ifaces = ifaces->next;
}
printf("\n");
}
/* checks the time then ticks and updates ISS */
static int32 clkval = 0;
void
check_time()
{
int32 iss(); /* initial sequence number */
int32 clksec();
if(clkval != clksec()){
clkval = clksec();
icmpclk();
tick();
(void)iss();
}
}
/* returns the number of seconds from system clock */
static int32
clksec()
{
long tloc;
time(&tloc);
return (tloc);
}
/* Initialize async port "dev" (adapted from PE1CHL) */
int
asy_init(dev,bufsize)
int16 dev;
unsigned bufsize;
{
register struct iorec *ip;
register struct asy *ap;
char *bufp;
/* char i_state; */
#ifdef DEBUG
printf("asy_init: dev=%d bufsize=%d\n",dev,bufsize);
fflush(stdout);
#endif
ap = &asy[dev];
if (ap->addr != RS232 && ap->addr != MIDI) {
printf("asy_init(%d): unknown interface\n",dev);
return -1;
}
/* force user to allocate more memory than he already has.
* If no memory is allocated, asy_stop() may behave funny...
*/
if (bufsize <= 256) /* only allocate a bigger buffer */
return -1;
if ((bufp = malloc(bufsize)) == NULLCHAR){
printf("asy_init(%d): no memory for rx buffer\n",dev);
return -1;
}
/* Save original IOREC values */
ip = Iorec((ap->addr)-1); /* Iorec wants AUX: = 0, MIDI = 2 */
Jdisint(12); /* disable RS-232 interrupt */
ap->in = ip;
memcpy(&ap->oldin,ip);
if (ap->addr == RS232) { /* increase RS-232 transmit buffer? */
ip++;
ap->out = ip;
memcpy(&ap->oldout,ip);
}
/* Set up receiver FIFO */
ap->in->ibuf = bufp;
ap->in->ibufsiz = bufsize;
ap->in->ibufhd = ap->in->ibuftl = 0;
ap->in->ibuflow = 0;
ap->in->ibufhi = bufsize;
if (ap->addr == RS232) {
/* clear transmitter FIFO */
ap->out->ibufhd = ap->out->ibuftl = 0;
ap->out->ibuflow = 0;
ap->out->ibufhi = ap->out->ibufsiz;
}
Jenabint(12); /* enable RS-232 interrupts */
if (ap->addr == RS232)
Rsconf(-1,0,-1,0,0,0); /* 8 bits, no parity */
#ifdef DEBUG
printf("asy_init: Iorecs in: 0x%lx out: 0x%lx\n",ap->in,ap->out);
printf(" inbuf: 0x%lx outbuf: 0x%lx\n",ap->in->ibuf,
ap->out->ibuf);
#endif
}
/* asy_stop restores old iorec and frees memory allocated to the RS-232/MIDI
* buffers. (from PE1CHL)
*/
int
asy_stop(iface)
struct interface *iface;
{
register struct asy *ap;
/* char i_state; */
#ifdef DEBUG
printf("asy_stop: iface=0x%lx dev=%d\n",iface,iface->dev);
fflush(stdout);
#endif
ap = &asy[iface->dev];
(void) Jdisint(12); /* disable RS-232 interrupts */
free(ap->in->ibuf); /* free the buffer */
/* Restore old iorecs */
memcpy(ap->in,&ap->oldin,sizeof(struct iorec));
if (ap->addr == RS232)
memcpy(ap->out,&ap->oldout,sizeof(struct iorec));
(void) Jenabint(12); /* enable RS-232 interrupts */
}
/* Set async line speed */
int
asy_speed(dev,speed)
int dev;
int speed;
{
int baud; /* int result; */
register int sp;
long sav_ssp;
if (speed <= 0 || dev >= nasy)
return -1;
asy[dev].speed = speed; /* shouldn't this be done in slip.c? */
switch (asy[dev].addr) {
case RS232:
switch (speed) {
case 300:
baud = 9; /* how slow can you get? :-) */
break;
case 1200:
baud = 7;
break;
case 2400:
baud = 4;
break;
case 4800:
baud = 2;
break;
case 9600:
baud = 1;
break;
case 19200:
baud = 0;
break;
default:
printf("asy_speed: unknown RS-232 speed (%d).\n",speed);
return -1;
}
(void) Rsconf(baud,0,0x88,-1,-1,-1); /* no flow control */
break;
case MIDI:
/* midi can run on 500000 or 614400Hz clock (hardware mod)
*/
switch (speed)
{
case 0x9600: /* = 38400 unsigned... (hardware mod) */
case 31250: /* normal MIDI baudrate */
sp = 0x95; /* /16 */
break;
case 9600: /* 9600 Baud requires hardware mod */
case 7812: /* 7812 Baud on an unmodified Atari */
sp = 0x96; /* /64 */
break;
default:
printf("asy_speed: unknown MIDI speed (%d).\n",speed);
return -1;
}
sav_ssp = Super(NULL); /* switch to Supervisor mode */
*((char *) 0xfffffc04L) = 0x03; /* Reset 6850 */
hiword(0); /* spend some time */
*((char *) 0xfffffc04L) = sp; /* set new divider ratio */
Super(sav_ssp); /* back to User mode */
break;
}
asy_flush(dev);
}
/* flush the input buffer of device dev (either aux: or midi).
* May be useful, because setting the baudrate causes an 0x7f to be sent.
*/
asy_flush(dev)
int dev;
{
int st_dev;
long c; /* Bconin returns a long */
st_dev = asy[dev].addr;
while (Bconstat(st_dev) == -1) { /* at least 1 char avlb */
c = Bconin(st_dev);
}
}
/* Send a buffer to serial transmitter */
asy_output(dev,buf,cnt)
unsigned dev;
char *buf;
unsigned short cnt;
{
int st_dev; /* int c; */
unsigned short i = 0;
if (dev >= nasy)
return -1;
st_dev = asy[dev].addr;
for (i = 0